home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 June: Reference Library / Dev.CD Jun 95 / Dev.CD Jun 95.toast / What's New? / New System Software Extensions / QuickDraw 3D ß / Programming / SampleCode / Modeller ƒ / Modeller_errors.c < prev    next >
Encoding:
Text File  |  1995-03-06  |  3.2 KB  |  136 lines  |  [TEXT/MPS ]

  1. //    Modeller_errors.c
  2. //
  3. //    Error handling routines for the modeller App.  Since this application was 
  4. //    designed primarily for demonstrating QuickDraw 3D, we'll just silently fail,
  5. //    and write escher messages to a file.
  6. //
  7. //    The debugging log is primarily there to help debug, so get the users to send the
  8. //    logfile in when they report problems.
  9. //        
  10. //    Author:        Nick Thompson, 11/24/94
  11. //
  12. //    Modification History:
  13. //
  14. //    11/26/94        nick        Initial Cut - based on code from spin
  15. //
  16. //    Copyright © 1992-94 Apple Computer, Inc., All Rights Reserved
  17. //
  18.  
  19. #include <stdlib.h>
  20. #include <stdarg.h>
  21. #include <stdio.h>
  22.  
  23. #include "QD3D.h"
  24. #ifndef ESCHER_VER_15
  25.     #define ESCHER_VER_15 1     /* THIS IS A BUG in Escher_Error.h! */
  26. #endif
  27. #include "QD3DErrors.h"
  28.  
  29. #include "Error_Lib.h"
  30. #include "Error_MesgLib.h"
  31.  
  32. #include "Modeller_errors.h"
  33.  
  34. static void MyErrorHandler( TQ3Error first, TQ3Error last, long reference);
  35. static void MyNoticeHandler(  TQ3Notice first, TQ3Notice last, long reference);
  36. static void MyWarningHandler(  TQ3Warning first, TQ3Warning last, long reference);
  37.  
  38. static FILE *pErrorFile = NULL;
  39.  
  40.  
  41. //-----------------------------------------------------------------------------
  42. //
  43. void MyError(
  44.     char     *fxnName, 
  45.     char     *string,
  46.     ...)
  47. {
  48.     char         message[512];
  49.     va_list     argList;
  50.  
  51.     va_start(argList, string);
  52.     vsprintf(message, string, argList);
  53.     va_end(argList);
  54.     
  55.     // we should allways have a console window availavle
  56.     sprintf("Error:%s:%s\n", fxnName, message);
  57.     
  58.     if (pErrorFile == NULL)
  59.         pErrorFile = fopen("error.output","w+");
  60.  
  61.     if (pErrorFile != NULL)
  62.         fputs(message, pErrorFile);
  63.     
  64. }
  65.  
  66. //-----------------------------------------------------------------------------
  67. //
  68. void MyErrorInit( void)
  69. {
  70.     Q3Error_Register( MyErrorHandler, NULL );
  71.     Q3Warning_Register( MyWarningHandler, NULL );
  72.     Q3Notice_Register( MyNoticeHandler, NULL );
  73. }
  74.  
  75. //-----------------------------------------------------------------------------
  76. //
  77. void MyErrorExit( void)
  78. {
  79.     if (pErrorFile != NULL)
  80.         fclose(pErrorFile);
  81. }
  82.  
  83. //-----------------------------------------------------------------------------
  84. // MyErrorHandler - handle warnings from QuickDraw 3d
  85. static void MyErrorHandler( TQ3Error     error, TQ3Error     error2 , long reference)
  86. {
  87.     char buf[512];
  88.     
  89.     sprintf(buf, "ERROR %d - %s\n",
  90.             error, getErrorString(error));
  91.  
  92.             
  93.     if (pErrorFile == NULL)
  94.         pErrorFile = fopen("error.output","w+");
  95.  
  96.     if (pErrorFile != NULL)
  97.         fputs(buf, pErrorFile);
  98. }
  99.  
  100. //-----------------------------------------------------------------------------
  101. // MyWarningHandler - handle warnings from QuickDraw 3d
  102.  
  103. static void MyWarningHandler( TQ3Warning     warning, TQ3Warning     warning2 , long reference)
  104. {
  105.     char buf[512];
  106.     
  107.     sprintf(buf, "WARNING %d - %s\n",
  108.             warning, getWarningString(warning));
  109.  
  110.             
  111.     if (pErrorFile == NULL)
  112.         pErrorFile = fopen("error.output","w+");
  113.  
  114.     if (pErrorFile != NULL)
  115.         fputs(buf, pErrorFile);
  116. }
  117.  
  118. //-----------------------------------------------------------------------------
  119. // MyNoticeHandler - handle notices from QuickDraw 3d
  120.  
  121. static void MyNoticeHandler( TQ3Notice     notice, TQ3Notice     notice2 , long reference)
  122. {
  123.     char buf[512];
  124.     
  125.     sprintf(buf, "NOTICE %d\n",
  126.             notice);
  127.  
  128.             
  129.     if (pErrorFile == NULL)
  130.         pErrorFile = fopen("error.output","w+");
  131.  
  132.     if (pErrorFile != NULL)
  133.         fputs(buf, pErrorFile);
  134. }
  135.  
  136.